package com.xipu.yygh.user.controller;

import com.xipu.yygh.common.result.R;
import com.xipu.yygh.manage.service.DepartmentService;
import com.xipu.yygh.manage.service.HospManageService;
import com.xipu.yygh.manage.service.ScheduleService;
import com.xipu.yygh.model.hosp.Hospital;
import com.xipu.yygh.model.hosp.Schedule;
import com.xipu.yygh.vo.hosp.DepartmentVo;
import com.xipu.yygh.vo.hosp.HospitalQueryVo;
import com.xipu.yygh.vo.hosp.ScheduleOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * description: 用户系统使用的医院接口
 * @author: gql
 * @date: 2022/05
 */
@RestController
@RequestMapping("/api/hosp/hospital")
public class UserController {

    /**
     * 医院信息表(Mongo)
     */
    @Autowired
    private HospManageService hospManageService;

    /**
     * 部门信息(Mongo)
     */
    @Autowired
    private DepartmentService departmentService;

    /**
     * 排班信息(Mongo)
     */
    @Autowired
    private ScheduleService scheduleService;

    /**
     * 获取分页列表
     * @param page 当前页
     * @param limit 每页记录数
     * @param hospitalQueryVo 条件查询对象
     * @return r
     */
    @GetMapping("/{page}/{limit}")
    public R index(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit,
            HospitalQueryVo hospitalQueryVo) {

        Page<Hospital> pageModel = this.hospManageService.selectPage(page, limit, hospitalQueryVo);
        return R.ok().data("pages", pageModel);
    }

    /**
     * 根据医院名称查询医院列表
     * @param hosname 医院名称
     * @return r
     */
    @GetMapping("/findByHosname/{hosname}")
    public R findByHosname(
            @PathVariable(value = "hosname") String hosname) {
        List<Hospital> list = this.hospManageService.findByHosname(hosname);
        return R.ok().data("list", list);
    }

    /**
     * 根据医院编号获取科室列表
     * @param hoscode 医院编号
     * @return r
     */
    @GetMapping("department/{hoscode}")
    public R index(@PathVariable("hoscode") String hoscode) {
        List<DepartmentVo> list = this.departmentService.findDeptTree(hoscode);
        return R.ok().data("list", list);
    }

    /**
     * 获取医院预约挂号详情
     * @param hoscode 医院编号
     * @return r
     */
    @GetMapping("{hoscode}")
    public R item(
            @PathVariable("hoscode") String hoscode) {
        Map<String, Object> map = this.hospManageService.getHospDetail(hoscode);
        return R.ok().data(map);
    }

    /**
     * 获取可预约排班数据
     * @param page 当前页
     * @param limit 每页记录数
     * @param hoscode 医院编号
     * @param depcode 科室编号
     * @return 可预约排班数据
     */
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {
        Map<String, Object> map = this.scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return R.ok().data(map);
    }

    /**
     * 获取排班数据
     * @param hoscode 医院编号
     * @param depcode 部门编号
     * @param workDate 工作日期
     * @return r
     */
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        List<Schedule> scheduleList = this.scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList", scheduleList);
    }

    /**
     * 获取排班详情
     * @param id 排班Id
     * @return r
     */
    @GetMapping("getSchedule/{id}")
    public R getScheduleList(@PathVariable String id) {
        Schedule schedule = this.scheduleService.getByScheduleId(id);
        return R.ok().data("schedule", schedule);
    }

    /**
     * 获取排班详情数据
     * @param scheduleId 排班Id
     * @return 排班详情Vo
     */
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @PathVariable("scheduleId") String scheduleId) {
        return this.scheduleService.getScheduleOrderVo(scheduleId);
    }

}
